package com.dongjiantong.quarantine.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.dongjiantong.quarantine.mapper.DjtBreedReportsMapper;
import com.dongjiantong.quarantine.model.DjtBreedReports;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by mz on 13/11/17.
 *
 */
@Slf4j
@Service(version = "1.0.0")
public class DjtBreedReportsReadServiceImpl extends ServiceMybatis<DjtBreedReports> implements DjtBreedReportsReadService{

    @Resource
    private DjtBreedReportsMapper djtBreedReportsMapper;

    /**
     * 根据id查询单据
     *
     * @param id 单据ID
     * @return DjtBreedReports
     */
    @Override
    public DjtBreedReports findById(Long id) {
        return djtBreedReportsMapper.selectByPrimaryKey(id);
    }

    /**
     * 养殖端的分页查询
     *
     * @param pageNum  页码
     * @param pageSize 每页条数
     * @param map      参数
     * @return PageInfo<DjtBreedReports>
     */
    @Override
    public PageInfo<DjtBreedReports> pagingForFarm(Integer pageNum, Integer pageSize, Map<String , Object> map) {

        PageHelper.startPage(pageNum, pageSize);

        List<DjtBreedReports> djtBreedReportsList = djtBreedReportsMapper.selectListForFarm(map);

        PageInfo<DjtBreedReports> breedReportsPageInfo = new PageInfo<DjtBreedReports>(djtBreedReportsList);
        return breedReportsPageInfo;
    }

    /**
     * 政府端的分页查询
     *
     * @param pageNum  页码
     * @param pageSize 每页条数
     * @param map      参数
     * @return PageInfo<DjtBreedReports>
     */
    @Override
    public PageInfo<DjtBreedReports> pagingForGOV(Integer pageNum, Integer pageSize, Map<String , Object> map) {

        if(map == null){
            map = Maps.newHashMap();
        }

        PageHelper.startPage(pageNum, pageSize);

        List<DjtBreedReports> djtBreedReportsList = djtBreedReportsMapper.selectListForGOV(map);

        PageInfo<DjtBreedReports> breedReportsPageInfo = new PageInfo<DjtBreedReports>(djtBreedReportsList);
        return breedReportsPageInfo;
    }

    /**
     * 获取但钱单据状态
     *
     * @param id 单据主键id
     * @return Integer status
     */
    @Override
    public Integer findStatusById(Long id) {
        return djtBreedReportsMapper.findStatusById(id);
    }

    @Override
    public PageInfo<DjtBreedReports> pagingForWeb(Integer pageNum, Integer pageSize, Map<String, Object> map) {
        if(map == null){
            map = Maps.newHashMap();
        }

        PageHelper.startPage(pageNum, pageSize);

        List<DjtBreedReports> djtBreedReportsList = djtBreedReportsMapper.selectListForWeb(map);

        PageInfo<DjtBreedReports> breedReportsPageInfo = new PageInfo<DjtBreedReports>(djtBreedReportsList);
        return breedReportsPageInfo;
    }

    @Override
    public List<Map<String, Object>> applyTop10ByArea(Map<String, Object> map) {
        return djtBreedReportsMapper.applyTop10ByArea(map);
    }

    @Override
    public List<Map<String, Object>> applyTop10ByApplyStation(Map<String, Object> map) {
        return djtBreedReportsMapper.applyTop10ByApplyStation(map);
    }

    @Override
    public List<Map<String, Object>> findSumByIsToLocal(Map<String, Object> map) {
        return djtBreedReportsMapper.findSumByIsToLocal(map);
    }

    @Override
    public Map<String, Object> findSumForWebDataAnalysis(Map<String, Object> map) {
        return djtBreedReportsMapper.findSumForWebDataAnalysis(map);
    }

    @Override
    public List<Map<String, Object>> sumGroupByReceive(Map<String, Object> map) {
        return djtBreedReportsMapper.sumGroupByReceive(map);
    }

    @Override
    public List<Map<String, Object>> sumGroupByDeliver(Map<String, Object> map) {
        return djtBreedReportsMapper.sumGroupByDeliver(map);
    }

    @Override
    public List<Map<String, Object>> findSumByIsToLocalAndMonth(Map<String, Object> map) {
        return djtBreedReportsMapper.findSumByIsToLocalAndMonth(map);
    }

    @Override
    public Map<String, Object> findSumForWebDataAnalysisAndMonth(Map<String, Object> map) {
        return djtBreedReportsMapper.findSumForWebDataAnalysisAndMonth(map);
    }

    @Override
    public Map<String, Object> selectSum(Map<String, Object> map) {
        return djtBreedReportsMapper.selectSum(map);
    }
}
